import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from '../views/Main.vue'
import HeritageIndustry from '../views/display.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',//主页面
    name: 'Main',
    component: Main,
    children: [

      {
        path: "/heritage/industry",
        component: HeritageIndustry
      },
      {
        path: "/FireBuffer",
        component: () => import('../views/FireBuffer.vue')
      },
      {
        path: "/DataFire",
        component: () => import('../views/DataFire.vue')
      },
      // 数据维护
      {
        path: '/FireHotMap',
        component: () => import('../views/FireHotMap.vue')
      },
    ]

  },
  {
    path: "/heritage/login",//登陆页面
    component: () => import('../views/LoginUser.vue')
  },
]
const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  const username = sessionStorage.getItem('username')
  const isPre = sessionStorage.getItem('isOk')
  if (isPre === null) {
    next('/noPre')
  } else {
    if (to.path !== "/heritage/login" && to.path !== "/heritage/postUser" && username === null) next("/heritage/login");
    next();
  }
})

export default router
